package com.atguigu.cloud.controller;

import com.atguigu.cloud.entities.Pay;
import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.service.PayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: daiziru
 * @createDate: 2024/3/1 20:13
 */
@Tag(name = "支付微服务模块",description = "支付CRUD")
@RestController
public class PayController {

    @Resource
    private PayService payService;

    @Operation(summary = "新增", description = "新增支付流水方法")
    @PostMapping(value = "/pay/add")
    public ResultData<String> addPay(@RequestBody Pay pay){
        System.out.println(pay.toString());
        int i = payService.add(pay);
        return ResultData.success("成功插入记录，返回值："+i);
    }

    @Operation(summary = "删除", description = "删除支付流水方法")
    @DeleteMapping(value = "/pay/delete/{id}")
    public ResultData<Integer> deletePay(@PathVariable("id") Integer id) {
        int delete = payService.delete(id);
        return ResultData.success(delete);
    }

    @Operation(summary = "更新", description = "更新支付流水方法")
    @PutMapping(value = "/pay/update")
    public ResultData<String> updatePay(@RequestBody PayDTO payDTO){
        Pay pay = new Pay();
        BeanUtils.copyProperties(payDTO, pay);
        int i = payService.update(pay);
        return ResultData.success("成功修改记录，返回值："+i);
    }

    @Operation(summary = "查询", description = "查询单个支付流水方法")
    @GetMapping(value = "/pay/get/{id}")
    public ResultData<Pay> getById(@PathVariable("id") Integer id){
        Pay pay = payService.getById(id);
        return ResultData.success(pay);
    }
    @Operation(summary = "查询所有", description = "查询所有支付流水方法")
    @GetMapping(value = "/pay/getAll")
    public ResultData<List<Pay>> getAll() {
        List<Pay> payList = payService.getAll();
        return ResultData.success(payList);
    }

    @Value("${server.port}")
    private String port;

    @GetMapping(value = "/pay/get/info")
    private String getInfoByConsul(@Value("${wuyan.info}") String wuyanInfo)
    {
        return "wuyan: "+ wuyanInfo + "\t" +"port: "+port;
    }


}
